/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package genomemap.tagging.analysis;

import genomemap.data.Clone;
import genomemap.data.ComplementationData;
import genomemap.data.DataSource;
import genomemap.data.Gene;

import java.util.*;
import java.util.logging.Logger;

/**
 * A tag analysis class is associated with a tagging strategy in analyzing how beneficial
 * is going to be the tagging strategy with respect to the genome data being used. This class
 * analyzes the <code>ComplementationTaggStrategy</code> class.
 * <p>
 * It checks for the following points:
 * <ul>
 * <li>checks if genes in the complementation data are present in the genomic database. The genes that
 * are not present are not going to be useful for tagging purposes.
 * <li>similarly check for clones in the complementation data.
 * </ul>
 * <p>
 * A report of the analysis should cover the following points:
 * <ul>
 * <li> Logger.info: Gene X is present in Chromosome XXX (a single chromosome). A single gene (it`s name) can`t appear
 * twice in the same species. That check belongs to the data integrity tests.
 * <li>Logger.warn: Gene X is not found in any chromosomes.
 * <li>Logger.info: Clone X is present in Chromosomes X1,X2,...
 * </ul>Logger.warn: Clone X is not found in any chromosomes.
 * @author Susanta Tewari <stewari@yahoo.com>
 */
public class ComplTagAnalysis {

    /** Field description */
    private static final Logger logger = Logger.getLogger(ComplTagAnalysis.class.getName());

    /** Field description */
    private final Map<String, Collection<String>> compl_data;

    /**
     * Constructs ...
     *
     * @param complementationData description
     */
    public ComplTagAnalysis(ComplementationData complementationData) {
        this.compl_data = complementationData.getGeneCloneTagData();
    }

    public void runAnalysis() {

        Set<String> complGeneLabels         = compl_data.keySet();
        Collection<String> complCloneLabels = new ArrayList<>();

        for (Collection cloneLabels : compl_data.values()) {

            complCloneLabels.addAll(cloneLabels);
        }

        Collection<Gene> allGenes   = new ArrayList<>();
        Collection<Clone> allClones = new ArrayList<>();

        for (int i = 0; i < 7; i++) {

            int ch_id = i + 1;

            allGenes.addAll(DataSource.getGDataSource(ch_id).getFullGeneSet());
            allClones.addAll(DataSource.getPDataSource(ch_id).getCloneSet());
        }


        // check the genes by their labels , if they are availabale in the database
        for (Iterator<String> it = complGeneLabels.iterator(); it.hasNext(); ) {

            String geneLabel = it.next();
            boolean found    = false;

            for (Iterator<Gene> itGene = allGenes.iterator(); itGene.hasNext(); ) {

                Gene gene = itGene.next();

                if (gene.getLabel().equals(geneLabel)) {

                    found = true;

                    logger.info("Gene " + geneLabel + " is present in Chromosome: "
                                + gene.getChId());

                    break;
                }
            }

            if (!found) {


                // logger.info("Gene " + geneLabel + " is NOT present in any Chromosomes: ");
            }
        }
    }
}
